﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Campus.Main.Basic.Settings;
using Campus.Report.ReportForm;
using Microsoft.Reporting.WinForms;
using dbcntn;

namespace Campus.Main.Basic
{
    public partial class KayitSilderenler : DefaultForm
    {
        public string Quer { get; set; }
        
        public KayitSilderenler()
        {
            InitializeComponent();
            aToDb=new ConnectionToDb(Helper.ConnectionString);
            
        }
        public override void Initialize()
        {
            comboBox1.SelectedIndex = 0;
            comboBox1.Enabled = false;
            textBox2.Enabled = false;
            textBox3.Enabled = false;
            checkBox2.Checked = checkBox3.Checked = checkBox4.Checked = false;
            aToDb.AddItemDBGridView(dataGridView1,Query.Arsiv);
        }

        private void KayitSilderenler_Load(object sender, EventArgs e)
        {
            //Quer = Query.Arsiv;
            Initialize();
        }


        private void checkBox2_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox2.Checked)
            {
                textBox2.Enabled = true;
                textBox2_TextChanged(null, null);
            }
            else
            {
                Initialize();
            }
        }

        private void checkBox3_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox3.Checked)
            {
                textBox3.Enabled = true;
            }
            else
            {
                Initialize();
            }
        }

        private void checkBox4_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox4.Checked)
            {
                comboBox1.Enabled = true;
                textBox2_TextChanged(null,null);
            }
            else
            {
                Initialize();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (dataGridView1.DataSource != null)
            {
                ReportForm f = new ReportForm();
                f.reportViewer1.ProcessingMode = ProcessingMode.Local;
                f.reportViewer1.LocalReport.ReportPath = "ReportTemplate/ArsivReport.rdlc";

                f.reportViewer1.LocalReport.DataSources.Clear();
                ogrenci2006_dboDataSet1.Clear();
                f.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1",dataGridView1.DataSource));//aToDb.GetDataSources(ogrenci2006_dboDataSet1,"Arsiv",Query.Arsiv)));
                f.ShowDialog();
            }
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {
            string query1 = Query.Arsiv;
            if (checkBox2.Checked)
            {
                query1 += " and a.name like '" + textBox2.Text + "%'";
            }
            if (checkBox3.Checked)
            {
                query1 += " and a.student_id like '" + textBox3.Text + "%'";
            }
            if (comboBox1.SelectedIndex > -1)
            {
                query1 += " and a.donem like ('" + comboBox1.SelectedItem + "')";
            }
            Quer = query1;
            aToDb.AddItemDBGridView(dataGridView1, Quer);
        }

        private void textBox3_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = (e.KeyChar < 48 || e.KeyChar > 57) && e.KeyChar != 8&&e.KeyChar!=46;
        }
    }
}
